﻿<UserControl x:Class="Citrix.XaAdminMobile.ViewCommon.ServersView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vm="clr-namespace:Citrix.XaAdminMobile.ViewModel"
             xmlns:cmp="clr-namespace:Citrix.Cmp;assembly=Citrix.Cmp.WPF"
             xmlns:res="clr-namespace:Citrix.XaAdminMobile.Resources"
             xmlns:prop="clr-namespace:Citrix.XaAdminMobile.Properties"
             mc:Ignorable="d" FocusVisualStyle="{x:Null}"
             d:DesignHeight="300" d:DesignWidth="300">
  <UserControl.Resources>

    <!-- The layout for display a summary of a single server. -->
    <DataTemplate DataType="{x:Type vm:ServerViewModel}">
      <Button x:Name="TheButton"
              Style="{DynamicResource ListItemDisplayButtonStyle}" Padding="5,10"
              HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch"
              Command="{Binding DisplayServerDetailsCommand}">
        <Grid>
          <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
          </Grid.ColumnDefinitions>
        
          <!-- Left column displays the server name and session count. -->
          <Grid Margin="0,0,5,0">
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="5"/>
              <RowDefinition Height="*"/>
            </Grid.RowDefinitions>

            <TextBlock x:Name="Server"  Text="{Binding Name}" FontSize="18"/>
            <StackPanel Grid.Row="2" Orientation="Horizontal">
              <TextBlock x:Name="SessionsLabel"  Text="{x:Static prop:Resources.ServerSessionCountLabel}" Foreground="Gray"
                         FontSize="14"/>
              <TextBlock x:Name="SessionCount" Text="{Binding SessionCount}" FontSize="14"/>  
            </StackPanel>
          </Grid>
          
          <!-- Misc server status items. -->
          <Grid Grid.Column="2">
            <Grid.RowDefinitions>
              <RowDefinition/>
              <RowDefinition/>
              <RowDefinition/>
              <RowDefinition/>
            </Grid.RowDefinitions>

            <!-- Logons enabled state -->
            <TextBlock x:Name="LogonsEnabledLabel"  Grid.Row="0"
                        Text="{x:Static prop:Resources.LogonsEnabledTag}"
                        Foreground="Gray" VerticalAlignment="Center"
                        TextAlignment="Right"/>
            <TextBlock x:Name="LogonsEnabled"  Grid.Row="1"
                        Text="{Binding LogonsEnabled}"
                        Foreground="Black" VerticalAlignment="Center"
                        TextAlignment="Right"/>

            <!-- PCM mode -->
            <TextBlock x:Name="PcmLabel"  Grid.Row="2"
                        Text="{x:Static prop:Resources.PowerStateTag}"
                        Foreground="Gray" VerticalAlignment="Center"
                        TextAlignment="Right"/>
            <TextBlock x:Name="PcmState"  Grid.Row="3"
                        Text="{Binding PowerCapManagementMode}"
                        Foreground="Black" VerticalAlignment="Center"
                        TextAlignment="Right"/>
          </Grid>

          <!-- Displays the server load on the right. -->
          <Grid Grid.Column="4">
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            
            <!-- XenApp load as a bar. -->
            <Border CornerRadius="2" BorderThickness="1" BorderBrush="Gray"
                    Width="35" Background="White">
              <Grid>
                <Grid.RowDefinitions>
                  <RowDefinition Height="{Binding LoadUnusedHeight}"/>
                  <RowDefinition Height="{Binding LoadUsedHeight}"/>
                </Grid.RowDefinitions>
                
                <!-- This border shows the load percentage. The height is controlled via bindings
                on the grid row dimensions. -->
                <Border Grid.Row="1" Background="LightBlue" CornerRadius="2"/>
              </Grid>
            </Border>

            <!-- The XenApp load index. -->
            <TextBlock
              x:Name="LoadIndex"
              Grid.Row="1" Text="{Binding Load}" Foreground="Gray"
              FontSize="12" TextAlignment="Center"/>
          </Grid>

          <!-- Right arrow icon -->
          <Path x:Name="ArrowPath" Style="{DynamicResource NextPageArrowStyle}"
                Grid.Column="5" Grid.RowSpan="3"
                Margin="8,0,0,0" VerticalAlignment="Center"/>

        </Grid>
      </Button>
      <DataTemplate.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
          <Setter TargetName="Server" Property="Foreground" Value="White"/>
          <Setter TargetName="SessionsLabel" Property="Foreground" Value="White"/>
          <Setter TargetName="SessionCount" Property="Foreground" Value="White"/>
          <Setter TargetName="LogonsEnabledLabel" Property="Foreground" Value="White"/>
          <Setter TargetName="LogonsEnabled" Property="Foreground" Value="White"/>
          <Setter TargetName="PcmLabel" Property="Foreground" Value="White"/>
          <Setter TargetName="PcmState" Property="Foreground" Value="White"/>
          <Setter TargetName="LoadIndex" Property="Foreground" Value="White"/>
          <Setter TargetName="ArrowPath" Property="Stroke" Value="White"/>
        </DataTrigger>
      </DataTemplate.Triggers>      
    </DataTemplate>
  </UserControl.Resources>
  
  <Grid>
    
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <!-- The master nav toolbar -->
    <ContentPresenter Content="{Binding NavToolbarViewModel}" />
    
    <!-- List of servers -->
    <ListBox
      Grid.Row="1"
      ItemsSource="{Binding Servers}"
      Style="{DynamicResource CleanListboxStyle}"
      SelectedItem="{Binding SelectedServer, Mode=OneWay}"/>
    
    <!-- Popup loading status. -->
    <res:LoadingStatus Grid.Row="2" DataContext="{Binding LoadingStatus}"/>

    <!-- Popup error status. -->
    <res:ErrorStatusView Grid.Row="3" DataContext="{Binding ErrorStatus}"/>
    
    <!-- Bottom toolbar. -->
    <Border Grid.Row="4" Style="{DynamicResource ToolbarBorderStyle}">
      <Grid>

        <Grid.ColumnDefinitions>
          <ColumnDefinition/>
          <ColumnDefinition/>
          <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Button Style="{DynamicResource PlainButtonStyle}"
                Content="{x:Static prop:Resources.RefreshServersLabel}"
                Command="{Binding RefreshCommand}"/>
      </Grid>
    </Border>

  </Grid>
</UserControl>
